import {createSlice} from '@reduxjs/toolkit';

const userSlice = createSlice({
  name: 'user',
  initialState: {
    user : {},
  },
  reducers: {
    // 设置用户信息
    setUserInfo: (state, action) => {
      const {payload} = action;
      state.user = payload;
    },
    // 清空用户信息
    clearUserInfo: (state, action) => {
      const {payload} = action;
      state.user = payload;
    },
  },
});
//从 userSlice.actions 中解构出 increment 和 decrement action creators，以便在应用程序中使用它们来分发相应的 action
export const {setUserInfo, clearUserInfo} = userSlice.actions;
//返回 reducer供combineReducers组装
export default userSlice.reducer;
